<template>
  <el-form :model="form" ref="formRef" label-width="80px">
    <el-form-item label="评价内容" prop="content" :rules="[{ required: true, message: '请输入评价' }]">
      <el-input v-model="form.content" type="textarea"/>
    </el-form-item>
    <el-button type="primary" @click="submitReview">提交评价</el-button>
  </el-form>
</template>

<script setup>
import { ref } from 'vue'
import { createReview } from '@/api/review'
import { ElMessage } from 'element-plus'
const props = defineProps(['serviceId'])
const emit = defineEmits(['review-success'])
const form = ref({ content: '' })
const formRef = ref(null)

async function submitReview() {
  formRef.value.validate(async (valid) => {
    if (!valid) return
    try {
      await createReview({
        serviceId: props.serviceId,
        content: form.value.content
      })
      ElMessage.success('评价成功')
      form.value.content = ''
      emit('review-success')
    } catch {
      ElMessage.error('评价失败')
    }
  })
}
</script> 